<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 16/5/19
 * Time: 上午9:21
 */
$api_service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($api_service_path . "public/index.php");
ob_end_clean();

if($argc != 2){
    echo $argv[0] . " [report type code] [shop] [begin date] [end date]\n";
    echo "---- report type code list ----\n";
    echo "1 - 结算工时分类统计\n";
    echo "2 - 进销存报表商品辅料库\n";
    echo "3 - 进销存报表商品配件库\n";
    echo "4 - 进销存报表已结辅料库\n";
    echo "5 - 进销存报表已结配件库\n";
    echo "6 - 毛利率分析\n";
    echo "7 - 盘点查询\n";
    echo "8 - 入库查询\n";
    echo "9 - 维修商品出库明细\n";
    echo "10 - 销售领用出库明细\n";
    exit;
}

//$type = $argv[1];
//$shop_id = $argv[2];
//$begin_date = $argv[3];
//$end_date = $argv[4];

$type = $argv[1];
$shop_id = 1;
$begin_date = '20160601';
$end_date = '20160602';


switch ($argv[1]){
    case 1:
        $report = Report::get_work_hour_report($begin_date,$end_date,$shop_id);
        echo "派工单号,结算日期,客户名称,车牌号,状态,订单技师,车辆品牌,车辆系列,车辆型号,VIN号,工时编码,名称,工时费,折扣,实际费用,修理工,班组,工时类型,三级分类,是否收费,工时定额,工时,接车员,品牌\n";
        break;
    case 2:
        break;
    case 3:
        break;
    case 4:
        break;
    case 5:
        break;
    case 6:
        $report = Report::get_profit_report($begin_date,$end_date,$shop_id);
        echo "派工单号,车牌号,客户,车型,车架号,维修收入,配件成本,单车毛利,毛利率,电话,车辆类型,行驶里程,修理工,结算日期,客户单位,油漆辅料成本,维修类型,保险到期年,保险到期月,保险到期日\n";
        break;
    case 7:
        $report = Report::get_check_inventory_supply($begin_date,$end_date,$shop_id);
        echo "单号,日期,库房,帐面数,盘点数,差异数,商品原编码,零件编号,零件名称,规格,单位,分类号,进价,小计,备注,操作员\n";
        break;
    case 8:
        $report = Report::get_storage_detail($begin_date,$end_date,$shop_id);
        echo "单号,日期,供货商名称,商品编码,商品名称,规格型号,单位,数量,含税进价,含税小计,商品分类,入库方式,库房名称,无税进价,无税小计,税率,付款方式,入库类型,货位,车型,产地,库房编码,备注,品牌代码,供货商编码,操作员ID,操作员,库管员ID,商品原编码\n";
        break;
    case 9:
        $report = Report::get_export_detail($begin_date,$end_date,$shop_id);
        echo "客户单位,派工单号,结算日期,车牌号,车型,出库日期,商品编号,商品名称,规格型号,单位,数量,金额,成本,利润,商品分类,出库类型,配件优惠,领料否,修理状态,入库批次,库房,修理工,接车员,货位,客户编码,是否收费,部门,商品原编码\n";
        break;
    case 10:
        break;
    case 11:
        $report = Report::get_order_parts_cost($begin_date,$end_date,$shop_id);
        echo "客户单位,派工单号,结算日期,车牌号,车型,出库日期,商品编号,商品名称,规格型号,单位,数量,金额,成本,利润,商品分类,出库类型,配件优惠,领料否,修理状态,入库批次,库房,修理工,接车员,货位,客户编码,是否收费,部门,商品原编码\n";
        break;
    default:
        echo "未知的报表类型\n";
        break;
}

foreach ($report as $_report){
    foreach ($_report as $value){
        if(is_array($value)){
            foreach ($value as $_value){
                foreach ($_value as $v){
                    echo $v . ",";
                }
            }
            echo "\n";
        }else{
            echo $value . ",";
        }
    }
    echo "\n";
}
